/**
 * Created by Shinelon on 2017/2/13.
 */
//使用mongo模块中的MongoClient功能
var MongoClient = require("mongodb").MongoClient;

//mongo配置
var connectionUrl = "mongodb://localhost:27017/myproject",
    sampleConection = 'people';

//插入一些个人信息给Mongo
var people = [{
    'name': "jjaiyy",
    "age": "23"
},{
    'name': 'Aimee',
    'age': '20'
}];

MongoClient.connect(connectionUrl, function (err, db) {
    console.log("Connect correctly to server.");

    //获取'people'集合，没有创建(相当于SQL中的表）
    var collection = db.collection(sampleConection);
    collection.insert(people, function (error, result) {
        if(!error){
            console.log("Success:" + result.ops.length + "people inserted！");
        }else{
            console.log("Some error was encountered!");
        }
        db.close();
    })
})


